-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: execute template methods directly #11
Conversation
engine.go
Outdated
@@ -160,6 +165,61 @@ func (e *Engine) RunScript(scriptFile string, data any) error { | |||
return nil | |||
} | |||
|
|||
// MethodExecutor returns an execution function that enables calls to global template methods from easytemplate. | |||
func (e *Engine) MethodExecutor(scriptFile string, data any) (func(fnName string, args ...interface{}) (interface{}, error), error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually just thinking of having a Run
that takes a method name and then someone would call RunScript
first followed by Run
to run additional methods in the environment setup by RunScript
.
That would maybe simplify the implementation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do that but don't we need to do this in RunScript which we don't right now
result := esbuild.Transform(string(script), esbuild.TransformOptions{
Target: esbuild.ES2015,
Loader: esbuild.LoaderTS,
Sourcemap: esbuild.SourceMapExternal,
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/speakeasy-api/easytemplate/blob/main/engine.go#L156
I'm not sure what the implications of adding that for every RunScript would be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preapproving based on the changes we discussed in a call happening
Allow template methods to be executed directly from easy template